// ActionScript file
// STUDENT
import components.GlavniPanel;

private function onLogInStudent(e:Event):void{
	panels.push(creator.createPanel("Glavni Panel", 0, 200, 300, screen.width-202, screen.height-380, true, false, "Panel"));
	panels.push(creator.createPanel("AKTIVNI KURSEVI", 0, 300, 250, 0, 0, true, false, "Kursevi"));		 			
	removeChild(panels[0]);
	showStudentPanels();
	panels[1].canClose(false);
	panels[2].canClose(false);
}
 		
private function showStudentPanels():void {
	addChild(googleInput);
	addChild(googleImage);
	addChild(wikipediaImage);
	addChild(wikipediaInput);
	addChild(rapidshareImage);
	addChild(rapidshareInput);
	for(var i:Number=1; i<panels.length; i++){
		addChild(panels[i]);
		panels[i].backButton.addEventListener(MouseEvent.CLICK, taskbarButtonClicked);
	 	//panels[i].backButton.addEventListener(MouseEvent.RIGHT_CLICK, taskbarButtonRightClicked);				
	 }
	 courses = new Courses(panels[2]);
	 glavniPanel = new GlavniPanel(panels[1]);
     service.sql = {type:"SELECT", a1:"k.naziv", a2:"k.id_kurs", a3:"k.sifra", a4:"k.opis", a5:"k.ects", a6:"p.bodovi", from:"kurs k, student s, studentskaprijava p, korisnik u", where:"p.student=s.id_student AND p.kurs=k.id_kurs AND u.id_username=s.username AND u.id_username="+lgIn.service.xml.result[0].id_username+" ORDER BY naziv ASC"};
	 service.addEventListener(service.MYSQL_RESULT, onCoursesResult);
	 service.startService();
}
			
private function onCoursesResult(e:Event):void{ 
	var xmlList:XMLList = service.xml.children();
	var xmlPom:String = "<root naziv='Kursevi'>";
	for (var i:int=0; i<xmlList.length(); i++) {
		xmlPom+="<kurs tip='0' bodovi='"+xmlList[i].bodovi+"' ects='"+xmlList[i].ects+"' sifra='"+xmlList[i].sifra+"' opis='"+xmlList[i].opis+"' naziv='"+xmlList[i].naziv+"' id_kurs='"+xmlList[i].id_kurs+"' />";
	}
	if(xmlList.length()==0){
		xmlPom+="<kurs tip='-1' naziv='Nema aktivnih kurseva'/>";
	}
	xmlPom+="</root>";
	var xml:XML=new XML(xmlPom);
	trace(xmlPom);
	courses.setDataProvider(xml);
	service.removeEventListener(service.MYSQL_RESULT, onCoursesResult);
}